package com.javafx06.controller;

import com.javafx06.Main;
import com.javafx06.util.StringUtil;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;

public class LoginController {

    @FXML
    private TextField account;

    @FXML
    private PasswordField password;

    @FXML
    private Label errorInfo;

    @FXML
    public void initialize(){

    }

    @FXML
    public void doLogin(){
        String accountText = account.getText();
        String passwordText = password.getText();
        if (StringUtil.isEmpty(accountText)) {
            errorInfo.setText("请输入账户！！！");
            errorInfo.setVisible(true);
            return;
        }

        if (StringUtil.isEmpty(passwordText)) {
            errorInfo.setText("请输入密码！！！");
            errorInfo.setVisible(true);
            return;
        }

        if (accountText.equals("admin") && passwordText.equals("admin")) {
            // 进入系统
            Main.changeView("view/main.fxml");
        } else {
            errorInfo.setText("账户/密码错误！！！");
            errorInfo.setVisible(true);
        }
    }
}
